package week_05.sort;

public class SelectionSort implements Sort {
    @Override
    public String toString() {
        return "SelectionSort:";
    }

    @Override
    public void sort(int[] nums) {
        int n = nums.length;
        for (int i = n - 1; i > 0; i--) {
            int max_index = 0;
            for (int j = 1; j <= i; j++) {
                max_index = (nums[j] > nums[max_index]) ? j : max_index;
            }
            swap(nums,max_index,i);
        }
    }

    public void swap(int[] nums, int i, int j) {
        int tmp = nums[i];
        nums[i] = nums[j];
        nums[j] = tmp;

    }
}
